<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('单据查询列表')" />
	<th:block th:include="include :: list-css" />
    <style>
       /* .layui-border-box{height: 400px !important;}
		.layui-table-body{height: 290px !important;} */
        .layui-tab-title{border-color: #ccc !important;}
        .layui-this{color: rgb(0, 135, 250) !important;background: none !important;}
        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after{border-color:  rgb(0, 135, 250) !important;}
        .mid-content {overflow: auto;}

        /* .layui-table-body{overflow-y: auto;overflow-x: hidden;} */
        /* .layui-table-body{} */
    </style>
</head>
<div class="main-content">
    <div class="content-right">
        <div class="search-top">
            <span>查询条件</span>
            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                <i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
            </a>
        </div>
        <div class="panel layout-expand layui-expand-east">
            <div class="panel-header">
                <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
                    <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
                    </a>
                </div>
            </div>
            <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
        </div>
        <form class="layui-form">
            <th:block th:include="listinclude :: searchRight('page')" />
        </form>
    </div>
    <div class="mid-content">
        <div class="layui-tab layui-tab-brief" lay-filter="demozf" style="margin-top: 0;">
            <ul class="layui-tab-title" >
                <li class="layui-this">线上付款</li>
                <li>线下付款</li>
            </ul>
            <div class="layui-tab-content"></div>
        </div>
        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
        <div class="spxx" style="display: none;">
            <div class="layui-tab layui-tab-brief demo2" lay-filter="demo2" style="position:relative;">
                <ul class="layui-tab-title">
                    <li class="layui-this">商品信息</li>
                    <li>操作日志</li>
                </ul>
                <button style="position:absolute;right:10px;top:5px;height: 30px;line-height: 30px;display: none;" class="layui-btn layui-btn-normal zjbcbtn">保存</button>
                <div class="layui-tab-content"></div>
            </div>
            <div id="sontable"><table class="layui-hide" id="pdhtable" lay-filter="pftable"></table></div>
        </div>

    </div>
</div>
<body class="no-skin">
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <span class="ishide1">
            <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn">
                <i class="dhicon dh-lujing1089"></i> 新增
            </div>
            <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="zfbth">
                <i class="dhicon dh-paypal"></i> 线上支付
            </div>
            <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn">
                <i class="dhicon dh-zu4250_2_2"></i> 导出
            </div>
        </span>
        <span class="ishide2" style="display: none;">
            <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn">
                <i class="dhicon dh-lujing1089"></i> 新增
            </div>
            <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn">
                <i class="dhicon dh-zu4250_2_2"></i> 导出
            </div>
			<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="printOfflinePayment">
				<i class="dhicon dh-zu4250_2_2"></i> 打印线下付款单
			</div>
        </span>
    </div>
</script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var gridColumns = [[${gridColumns}]],
        business = [[${purchase}]],
        buttonState = [[${buttonState}]],
        businessName = gridColumns.moduleAlias,
        passwordAuthentication = [[${passwordAuthentication}]],
        ali1688AppKey = [[${ali1688AppKey}]],
        ali1688EcpApiUrl = [[${ali1688EcpApiUrl}]],
        session = [[${session}]],
        moduleTable = [[${moduleTable}]];
    /*]]>*/
    var prefix = "/purchase/"+business;
	var tableUrl = prefix + "/list",
	openRowUrl = "/purchase/"+(business.split('/')[1]?business.split('/')[0]:business)+"/edit?nid=";
	exportUrl = prefix + "/export";
</script>
<!--<th:block th:include="listinclude :: purchase" />-->
<th:block th:include="include :: footer" />
<th:block th:include="include :: tableBtn" />
<th:block th:include="listinclude :: list-templeat" />
<th:block th:include="include :: searchJS" />
<th:block th:include="include :: listJS" />
<script th:src="@{/dhecp/js/queryCondition.js}"></script>

<script type="text/javascript">
    var element,thStr;
    var fieldWidth = {},		//导入列表字段宽度
        filedRequired = {},		//导入列表必填字段
        dateFiled = [],			//导入列表日期字段
        hasNull = false;		//导入数据必填字段有空值
    $.each(gridColumns.dictionaryForPageFieldList,function(i,v){
        fieldWidth[v.fields] = v.fieldFrontWidth
        if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
        if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
    })
    var $,layer,laydate,form,table,wherestr={};

    layui.use(['table','laydate','form','layer','jquery','element'], function () {
        $ = layui.$, layer = layui.layer,laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
        serachRender();//查询条件初始渲染集合
        changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
        //是否显示头部按钮
        var vtype=1
        $.tablelist.init({
            elem: '#dhtable'
            ,modalName: "采购付款"
            ,url: tableUrl
            ,updateUrl: prefix + "/edit?guid={id}"
            ,initSort: {field: 'createTime',type: 'asc'}
            ,totalRow: gridColumns.totalRow
            ,cols: [gridColumns.gridBody]
            ,toolbar: '#toolbar'
            ,height:'full-46'
            ,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
            ,parseData: function(res){ //res 即为原始返回的数据
                var objpage=sessionStorage.getItem(moduleTable+'checkdata')
                if(objpage){
                    objpage=JSON.parse(objpage)
                    res.data.map((v,i)=>{
                        objpage.map((n,m)=>{
                            if(v.guid==n.guid){
                                v.LAY_CHECKED=true
                            }
                        })
                    })
                }
            }
            ,done:function(res, curr, count){
                var ltv=this.elem.next('.layui-table-view');//当前table的dom
                res.data.length || count || ltv.find('.layui-table-header').css('display', 'inline-block');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
                res.data.length || count || ltv.find('.layui-table-box').css('overflow-x', 'auto');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
                if(vtype==1){
                    $('.ishide1').show()
                    $('.ishide2').hide()
                }else if(vtype==2){
                    $('.ishide1').hide()
                    $('.ishide2').show()
                }
                fixTotal(this);//修复合计行固定列问题
                rowheight(res, curr);//修复合计行固定列问题
                if(typeof listTableDone == 'function')listTableDone();//如果查询列表存在表格加载完成回调事件，则执行
            }
        });
        //监听排序事件
        table.on('sort(ftable)', function(obj){
            $.tablelist.sort('dhtable',obj);
        });

        //监听行双击事件
        table.on('rowDouble(ftable)', function (obj) {
            // window.location.href = "/business/productbasis/edit?guid="+obj.data.guid;
            if (vtype === 1){
                top.layui.index.openTabsPage(prefix+ "/edit?nid="+obj.data.nid,'线上付款单 - 修改')
            }else{
                top.layui.index.openTabsPage("purchase/offlinepayment/edit?nid="+obj.data.nid,'线下付款单 - 修改')
            }
        });

        //头工具栏事件
        table.on('toolbar(ftable)', function(obj){
            console.log("openRowUrl",openRowUrl)
            switch(obj.event){
                case 'addbtn':
                    if (vtype === 1){
                        parent.layui.index.openTabsPage(openRowUrl+'0', "线上付款单"+' - 新增');
                    }else{
                        parent.layui.index.openTabsPage(openRowUrl+'0', "线下付款单"+' - 新增');
                    }

                    break;
                case 'zfbth'://采购付款 线上支付
                    var objpage = sessionStorage.getItem(moduleTable + 'checkdata')
                    if (!objpage) {
                        layer.msg("请先选择数据！");
                    } else {
                        console.log("objpage",objpage)

                        $.modal.confirmCom('确定要跳转支付么？', function (result) {
                            var infoItems = JSON.parse(objpage)
                            if (infoItems.some(item => (item.isPay === '已付款'))) {
                                layer.msg("单据已付款,请务重复操作!");
                                return;
                            }
                            var orderID = ""
                            $.each(infoItems, function (i, v) {
                                orderID += (v.orderNumber !== "" && v.orderNumber !== null ? v.orderNumber + "," : "")
                            })
                            orderID = orderID.substring(0, orderID.length - 1)
                            if (orderID === "") return layer.msg("订单ID不可为空！");
                            var index = layer.load();
                            $.post(ali1688EcpApiUrl + '/api/1688/get1688AlipayUrl', {
                                'aliOrderNos': orderID,
                                userId: session.userId
                            }, function (result) {
                                if (result.success == true) {
                                    setTimeout(function () {
                                        sessionStorage.removeItem(moduleTable + 'checkdata');
                                        table.reload('dhtable', {page: {curr: 1}, where: getWherestr()});
                                    }, 1000);
                                    window.open(result.extendAttr);
                                    layer.closeAll();
                                    // layer.open({
                                    // 	type: 2,
                                    // 	area: [($(window).width() - 200)+'px', ($(window).height() - 100)+'px'],
                                    // 	fix: false,//不固定
                                    // 	offset: '10%',//距离顶部
                                    // 	maxmin: true,//最大最小化
                                    // 	shade: 0.3,//遮罩
                                    // 	title: '支付',
                                    // 	content: result.extendAttr,
                                    // 	btn: ['取消'],
                                    // 	shadeClose: true,// 弹层外区域关闭
                                    // });
                                } else {
                                    layer.alert(result.message, {icon: 2});

                                }
                                layer.close(index);//取消等待
                            });
                        });
                    }
                    break;
    			case 'printOfflinePayment'://打印线下付款单
    				alert(111);
    				console.log(111);
    				var objpage=sessionStorage.getItem(moduleTable+'checkdata')
    				if(!objpage || objpage == '[]'){
    					layer.msg("请选择一条数据！");
    					break;
    				}
    				var infoItems=JSON.parse(objpage);
    				if(infoItems.length > 1) {
    					layer.msg("只能选择一条数据！");
    					break;
    				}
    				$.operate.post('/purchase/offlinepayment/generatePDF',{bid: infoItems[0].bid},function(result){
    					if (result.code == 0){
    						window.open(result.data)
    						setTimeout(function(){
    							sessionStorage.setItem(moduleTable+'checkdata','')
    							table.reload('dhtable', {page: {curr: 1},where:getWherestr()});
    						}, 1000);
    					}
    				});
    				break;
    			case 'exportbtn'://导出
                    if (vtype === 1){
                        exportUrl = "payment/export"
                    }else{
                        exportUrl ="offlinepayment/export"
                    }
                    $.ajax({
                        url: exportUrl,
                        type: 'GET',
                        data: getWherestr(),
                        dataType: 'json',
                        beforeSend: function () {
                            showloadings(true);
                        },
                        success: function (result) {
                            if (result.code == 0) {
                                window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
                                parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
                            } else if (result.code == web_status.WARNING) {
                                $.modal.alertWarning(result.msg)
                            } else {
                                $.modal.alertError(result.msg);
                            }
                            showloadings(false);
                        }
                    });
    				break;
            };
        });

        table.on('row(ftable)', function (obj) {
            console.log(9999)
           comobj = obj
           comguid = obj.data.guid
            if(vtype==2){
                if (obj.tr.find('input[lay-type="layTableRadio"]').length) {//勾选行单选按钮，重置其他行勾选
                   obj.tr.find('input[lay-type="layTableRadio"]').prop("checked", true);//默认无法取消勾选
                   layui.each(table.cache.dhtable, function (i, item) {
                       if (obj.tr.data('index') === i) item.LAY_CHECKED = true;
                       else delete item.LAY_CHECKED;
                   });
               }
            }else{
               pddata(comobj)
            }
               
              

    });



        // 头部组装切换
        element.on('tab(demozf)', function(elem,a){
            var name=$(elem.elem.context).text()

            if(name==='线上付款'){
                tableUrl1 = prefix + "/list",
                vtype=1

            }else if(name==='线下付款'){
                tableUrl1 = "offlinepayment/list",
                vtype=2
            }

            $.get(prefix+"/switchover",{num:vtype},function(data){
                // 初始化表格
                $.tablelist.init({
                    elem: '#dhtable'
                    ,url: tableUrl1
                    , totalRow: data.totalRow
                    , cols: [data.gridBody]
                    , toolbar: '#toolbar'
                    , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
                    , height: '450'
                    , done: function (res, curr, count) {
                        listData1 = table.cache.dhtable;//每次重载都赋值更新表缓存
                        $('.spxx').hide()
                        $('.layui-table-body').eq(0).css('height', "75vh");
                        if(vtype === 1){
                            $('.ishide1').show()
                            $('.ishide2').hide()
                            openRowUrl = "/purchase/payment/edit?nid=";
                        }else if(vtype === 2){
                            $('.ishide1').hide()
                            $('.ishide2').show()
                            openRowUrl = "/purchase/offlinepayment/edit?nid=";
                        }
                    },success:function(a,b,c){
                        console.log(a,b,c,9999)
                    }
                });
              
                var cephalosome = document.getElementById("cephalosome");//获取所有的table
				var str = queryCondition(data.fixtype);
				cephalosome.innerHTML = str;
				form.render();
                serachRender()
            });
        });

    });



</script>
</body>
</html>
